package com.briup.day08;


import com.sun.xml.internal.ws.addressing.WsaActionUtil;

/**
 * instanceof   2边类型 必须具有继承关系类型
 * 输出结果： 由变量指向的对象类型是否符合判断类型
 * @author lining
 * @date 2024/1/17 14:44
 */
public class TestInstanceOf {
    public void method(Object o2){//o2 = new String("abc")
        if(o2 instanceof BasketBall){
            BasketBall b = (BasketBall) o2;//b = "abc"
        }
        if(o2 instanceof String){
            String s= (String) o2;

        }
    }


    public static void main(String[] args) {
        TestInstanceOf t = new TestInstanceOf();
        t.method("abc");


        Object o = new Student();
        //o指向对象是否是String类型
        System.out.println(o instanceof String);//false
        System.out.println(o instanceof Student);//true
        System.out.println(o instanceof Object);//true
        Student s = new Student();
//        System.out.println(s instanceof String);
//        System.out.println(s instanceof Teacher);
//        System.out.println(s instanceof Object);
//        System.out.println(s instanceof Person);
        Object o2 = new BasketBall();
        BasketBall b = (BasketBall) o2;

        String msg = new String("abc");

        msg.equals("abc"); // true
        msg.equals(new Student());//false if(student对象 instanceof String)
    }
}
